package org.rocky.consumer.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author Rocky
 * @date 2020/2/17 17:19
 */
@Component
@PropertySource("classpath:queues.properties")
public class ConsumeTopic {

    @RabbitHandler
    @RabbitListener(queues = "${today.rocky.prefix-topic-queue}", containerFactory="rabbitListenerContainerFactory")
    public void processPrefixQueue(Message message, Channel channel) throws IOException {
        System.out.println("Prefix Queue received msg : " + new String(message.getBody()));
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

    @RabbitHandler
    @RabbitListener(queues = "${today.rocky.suffix-topic-queue}", containerFactory="rabbitListenerContainerFactory")
    public void processSuffixQueue(Message message, Channel channel) throws IOException {
        System.out.println("Suffix Queue received msg : " +  new String(message.getBody()));
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }


}
